package com.example.shop_2212.fgviewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntityResult
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CategoryViewModel:BaseViewModel() {
    //返回值--一级二级共用
    val categorySuccess = MutableLiveData<CategoryEntityResult>()
    val categoryFail = MutableLiveData<String>()
    fun category(){
        viewModelScope.launch {
            try {
                categorySuccess.value = apiServer.category()
            }catch (e:Exception){
                categoryFail.value = e.message
            }
        }
    }

    //返回值---分类商品列表
    val success = MutableLiveData<GoodsEntityResult>()
    val fail = MutableLiveData<String>()
    fun cateDetail(
        cid: Int,
        keyword: String,
        limit: Int,
        news: Boolean,
        page: Int,
        priceOrder: String,
        salesOrder: String
    ) {
        viewModelScope.launch {
            try {
                success.value = apiServer.cateDetail(cid, keyword, limit, news, page, priceOrder, salesOrder)
            }catch (e:Exception){
                fail.value = e.message
            }
        }
    }
}